<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/6/17
 * Time: 15:20
 */

namespace Weixin\Service;


use Common\Common\Service;
use Weixin\Component\Cookie\CookieComponent;
use Weixin\Exception\WeixinException;
use Weixin\Request\Cookie\SetCookieRequest;

class SetCooieService implements Service
{
    public function run(SetCookieRequest $request = null)
    {
        if ($request->issetOpenId() == false) {
            throw new WeixinException(10001);
        }
        $openid = $request->getOpenid();
        $component = new CookieComponent();
        try {
            $component->setCookie($openid);
        } catch (WeixinException $e) {
            throw new WeixinException($e->getMessage(), $e->getCode());
        }
    }
}